package com.itheima.controller;

import com.itheima.domain.po.Emp;
import com.itheima.domain.query.EmpQueryParam;
import com.itheima.domain.vo.Result;
import com.itheima.service.EmpService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Resource
    private EmpService empService;

    @GetMapping
    public Result page(EmpQueryParam param) {
        log.info("员工列表查询条件：{}",param);

        return Result.success(empService.pageResult(param));
    }
    
    @PostMapping
    public Result save(@RequestBody Emp emp) {
        log.info("新增员工，员工信息：{}",emp);
        return Result.success(empService.saveEmp(emp));
    }
    
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids) {
        log.info("批量删除学生，{}",ids);
        return Result.success(empService.deleteEmp(ids));
    }
    
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据ID查询员工信息，id：{}",id);
        return Result.success(empService.queryEmpById(id));
    }
    
    @PutMapping
    public Result update(@RequestBody Emp emp) {
        log.info("修改员工信息，员工信息：{}",emp);
        return Result.success(empService.updateEmp(emp));
    }
}
